//
//  ViolationDetailViewController.m
//  carcareIOS
//
//  Created by ileo on 16/8/4.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "ViolationMapViewController.h"
#import "MapViolation.h"
#import "NetCar.h"
#import "CarModel.h"
#import "NetViolations.h"
#import "VioPunishmentView.h"

#define BOTTOM_HEIGHT (175)

@interface ViolationMapViewController ()

@property (nonatomic, strong) MapViolation *mapViolation;

@property (nonatomic, strong) UIButton *button;

@property (nonatomic, strong) VioModel *vioModel;

@property (nonatomic, strong) VioPunishmentView *punishmentView;
@property (nonatomic, strong) UILabel *vTimeL;
@property (nonatomic, strong) UILabel *vDetailL;
@property (nonatomic, strong) UILabel *vAddressL;

@end


@implementation ViolationMapViewController

-(void)viewDidLoad{
    [super viewDidLoad];
    self.title = @"违章详情";
    [self.view addSubview:self.mapViolation.mapView];
    
    UIView *bottomV = [[[UIView viewWithFrame:CGRectMake(0, __MAIN_HEIGHT_64 - BOTTOM_HEIGHT, __MAIN_WIDTH, BOTTOM_HEIGHT)] resetBorderWidth:0.5 borderColor:[Theme lineColor]] setupOnView:self.view];
    bottomV.backgroundColor = [UIColor whiteColor];
//    [bottomV addSubview:self.button];
//    self.button.top = 14 * __MAIN_RATIO_375;
//    self.button.right = __MAIN_WIDTH - 13 *__MAIN_RATIO_375;
    
    CGFloat gap = 20 * __MAIN_RATIO_375;
    self.punishmentView = [[[VioPunishmentView alloc] initWithFrame:CGRectMake(0,  0, __MAIN_WIDTH, 40) gap:gap] setupOnView:bottomV];
    [self.punishmentView resetBorderWidth:0.5 borderColor:[Theme lineColor]];
    
    self.vDetailL = [[UILabel labelWithFrame:CGRectMake(gap, self.punishmentView.bottom + 5, __MAIN_WIDTH - 50 * __MAIN_RATIO_375, 50) font:FONT_DEFAULT_Bold(15) text:nil textColor:COLOR_HEXSTRING(@"#2a2a2a")] setupOnView:bottomV];
    
    self.vDetailL.numberOfLines = 0;
    self.vAddressL = [[UILabel labelWithFrame:CGRectMake(gap, self.vDetailL.bottom + 5, self.vDetailL.width,40) font:FONT_DEFAULT_Light(14) text:nil textColor:COLOR_HEXSTRING(@"#616161")] setupOnView:bottomV];
    self.vAddressL.numberOfLines = 0;
    self.vTimeL = [[UILabel labelWithFrame:CGRectMake(gap, self.vAddressL.bottom + 9, self.vDetailL.width, 15) font:FONT_DEFAULT_Light(13) text:nil textColor:COLOR_HEXSTRING(@"#908f8f")] setupOnView:bottomV];
    
    [self setVioModel:self.vioModel];
}

-(void)setVioModel:(VioModel *)vioModel{
    _vioModel = vioModel;
    
    [self.punishmentView setPunishmentMoney:vioModel.money point:vioModel.point];
    self.vDetailL.text = vioModel.detail;
    self.vAddressL.text = vioModel.address;
    self.vTimeL.text = vioModel.showTime;
}

-(void)setVioCarModel:(VioCarModel *)vioCarModel index:(NSInteger)index{
    self.vioModel = vioCarModel.vioModels[index];
    __weak __typeof(self) wself = self;
    [NSTimer scheduledTimerWithTimeInterval:0.1 block:^{
        wself.mapViolation.vioModels = vioCarModel.vioModels;
        wself.mapViolation.ChoiceIndex = index;
        [wself.mapViolation showVioMap];
    } repeats:NO];
    
}

-(MapViolation *)mapViolation{
    if (!_mapViolation) {
        _mapViolation = [[MapViolation alloc] init];
        _mapViolation.mapView.frame = CGRectMake(0, 0, __MAIN_WIDTH, __MAIN_HEIGHT - BOTTOM_HEIGHT);
        __weak __typeof(self) wself = self;
        _mapViolation.Select = ^(VioModel *vioModel){
            wself.vioModel = vioModel;
        };
    }
    return _mapViolation;
}

-(UIButton *)button{
    if (!_button) {
//        __weak __typeof(self) wself = self;
//        _button = [[[UIButton buttonWithFrame:CGRectMake(0, 0, 68 * __MAIN_RATIO_375, 27 * __MAIN_RATIO_375) title:@"查看轨迹" textColor:COLOR_HEXSTRING(@"#1f90e5") font:FONT_DEFAULT_Light(13 * __MAIN_RATIO_375) click:^{
//        }] resetBorderWidth:0.5 borderColor:COLOR_HEXSTRING(@"#1f90e5")] resetCornerRadius:2];
    }
    return _button;
}

@end
